$(function(){
	$(".selector").each(function() {
		 $(this).selectorInit();
	});
	
	$("#c_module").click(function(){
		$("#create_module").show();
		$("#create_submodule").hide();
		$("#create_webpage").hide();
		$("#create_power").hide();
		$(".create_result").hide();
	});
	$("#c_submodule").click(function(){
		$("#create_module").hide();
		$("#create_submodule").show();
		$("#create_webpage").hide();
		$("#create_power").hide();
		$(".create_result").hide();
		var url = '/power/aj_power.php?action=initModuleJson';
		$.get(url, function(json){
			window[$("#submodule_plat").attr('selectorData')] = json.module_str;
			$("#submodule_plat").selectorInit();
		}, 'json');	
	});
	$("#c_webpage").click(function(){
		$("#create_module").hide();
		$("#create_submodule").hide();
		$("#create_webpage").show();
		$("#create_power").hide();
		$(".create_result").hide();
		var url = '/power/aj_power.php?action=initSubmoduleJson';
		$.get(url, function(json){
			window[$("#webpage_plat").attr('selectorData')] = json.submodule_str;
			$("#webpage_plat").selectorInit();
		}, 'json');		
	});
	$("#c_power").click(function(){
		$("#create_module").hide();
		$("#create_submodule").hide();
		$("#create_webpage").hide();
		$("#create_power").show();
		$(".create_result").hide();
		var url = '/power/aj_power.php?action=initWebpageJson';
		$.get(url, function(json){
			window[$("#power_plat").attr('selectorData')] = json.webpage_str;
			$("#power_plat").selectorInit();
		}, 'json');	
	});
	
	
	$("#module_submit").click(function(){
		var url = "/power/aj_power.php";
		var module_plat = $("select[name='module_plat']").val();
		var module_title = $("input[name='module_title']").val();
		var action = 'createModule';
		post = {module_plat:module_plat, module_title:module_title, action:action};
		$.post(url, post, function(json){
			if (json.status == 1) {
				$("#module_success table tbody").remove();
				var html = '<tbody><tr>' + json.info.id + json.info.title + json.info.platform + json.info.ctime + json.info.cstaff + '</tr></tbody>';
				$("#module_success table").append(html);
				$("#module_success").show();
				$("#create_fail").hide();
			} else {
				var error_msg = json.msg;
				$("#create_fail font").text(error_msg);
				$("#create_fail").show();
				$("#module_success").hide();
			}
		}, "json");
	});
	$("#submodule_submit").click(function(){
		var url = "/power/aj_power.php";
		var submodule_plat = $("select[name='submodule_plat']").val();
		var sub_module = $("select[name='sub_module']").val();
		var submodule_title = $("input[name='submodule_title']").val();
		var action = 'createSubmodule';
		var sub_module_name = $("select[name='sub_module'] option:selected").text();
		post = {submodule_plat:submodule_plat, sub_module:sub_module, submodule_title:submodule_title, action:action, sub_module_name:sub_module_name};
		$.post(url, post, function(json){
			if (json.status == 1) {
				$("#submodule_success table tbody").remove();
				var html = '<tbody><tr>' + json.info.id + json.info.title + json.info.module + json.info.platform + json.info.ctime + json.info.cstaff + '</tr></tbody>';
				$("#submodule_success table").append(html);
				$("#submodule_success").show();
				$("#create_fail").hide();
			} else {
				var error_msg = json.msg;
				$("#create_fail font").text(error_msg);
				$("#create_fail").show();
				$("#submodule_success").hide();
			}
		}, "json");
	});
	$("#webpage_submit").click(function(){
		var url = "/power/aj_power.php";
		var webpage_plat = $("select[name='webpage_plat']").val();
		var webpage_module = $("select[name='webpage_module']").val();
		var webpage_submodule = $("select[name='webpage_submodule']").val();
		var webpage_type = $("input[name='webpage_type']:checked").val();
		var webpage_title = $("input[name='webpage_title']").val();
		var webpage_developer = $("input[name='webpage_developer']").val();
		var action = 'createWebpage';
		var wb_module_name = $("select[name='webpage_module'] option:selected").text();
		var wb_submodule_name = $("select[name='webpage_submodule'] option:selected").text();
		var wb_type_name = $("input[name='webpage_type']:checked+em").text();
		post = {webpage_plat:webpage_plat, webpage_module:webpage_module, webpage_submodule:webpage_submodule, webpage_type:webpage_type,
				webpage_title:webpage_title, webpage_developer:webpage_developer, action:action, 
				wb_module_name:wb_module_name, wb_submodule_name:wb_submodule_name, wb_type_name:wb_type_name};
		$.post(url, post, function(json){
			if (json.status == 1) {
				$("#webpage_success table tbody").remove();
				var html = '<tbody><tr>' + json.info.id + json.info.type + json.info.title + json.info.submodule + json.info.module + json.info.platform + json.info.ctime + json.info.cstaff + '</tr></tbody>';
				$("#webpage_success table").append(html);
				$("#webpage_success").show();
				$("#create_fail").hide();
			} else {
				var error_msg = json.msg;
				$("#create_fail font").text(error_msg);
				$("#create_fail").show();
				$("#webpage_success").hide();
			}
		}, "json");
	});
	$("#power_submit").click(function(){
		var url = "/power/aj_power.php";
		var power_plat = $("select[name='power_plat']").val();
		var power_module = $("select[name='power_module']").val();
		var power_submodule = $("select[name='power_submodule']").val();
		var power_webpage = $("select[name='power_webpage']").val();
		var power_title = $("input[name='power_title']").val();
		var action = 'createPower';
		var pw_module_name = $("select[name='power_module'] option:selected").text();
		var pw_submodule_name = $("select[name='power_submodule'] option:selected").text();
		var pw_webpage_name = $("select[name='power_webpage'] option:selected").text();
		post = {power_plat:power_plat, power_module:power_module, power_submodule:power_submodule, power_webpage:power_webpage, power_title:power_title, 
				action:action, pw_module_name:pw_module_name, pw_submodule_name:pw_submodule_name, pw_webpage_name:pw_webpage_name};
		$.post(url, post, function(json){
			if (json.status == 1) {
				$("#power_success table tbody").remove();
				var html = '<tbody><tr>' + json.info.id + json.info.title + json.info.webpage + json.info.submodule + json.info.module + json.info.platform + json.info.ctime + json.info.cstaff + '</tr></tbody>';
				$("#power_success table").append(html);
				$("#power_success").show();
				$("#create_fail").hide();
			} else {
				var error_msg = json.msg;
				$("#create_fail font").text(error_msg);
				$("#create_fail").show();
				$("#power_success").hide();
			}
		}, "json");
	});
	$("#search_by_id").click(function(){
		if(0 == $("select[name='search_id_type']").val()  && '' != $("input[name='search_id_value']").val()){
			showCommonLayer('请选择id类型', 1);
		}else if(0 != $("select[name='search_id_type']").val() && '' == $("input[name='search_id_value']").val()){
			showCommonLayer('请填写id内容', 1);
		}else{
			$("form[name='search_form1']").submit();
		}
	});
	$("#search_by_name").click(function(){
		if(0 == $("select[name='search_name_type']").val()  && '' != $("input[name='search_name_value']").val()){
			showCommonLayer('请选择名称类型', 1);
		}else if(0 != $("select[name='search_name_type']").val() && '' == $("input[name='search_name_value']").val()){
			showCommonLayer('请填写名称内容', 1);
		}else{
			$("form[name='search_form2']").submit();
		}
	});
})
